from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
# 权限的模型类
from django.contrib.auth.models import Permission, ContentType

from meiduo_admin.serializers.permission import PermissionSerializer, ContentTypeSerializer
from meiduo_admin.utils import PageNum1


class PermissionViewSet(ModelViewSet):
    queryset = Permission.objects.all()
    serializer_class = PermissionSerializer
    pagination_class = PageNum1

    # @action(methods=['get'], detail=True)
    def contenttype(self, request):
        data = ContentType.objects.all()
        ser = ContentTypeSerializer(data, many=True)
        return Response(ser.data)
